{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Solution(object):\n",
    "    def addDigits(self, num):\n",
    "        \"\"\"\n",
    "        :type num: int\n",
    "        :rtype: int\n",
    "        \"\"\"\n",
    "        if num == 0:\n",
    "            return 0\n",
    "        # Easy to find the rule\n",
    "        return (num - 1) % 9 + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "100 True\n",
      "101 True\n",
      "102 True\n",
      "103 True\n",
      "104 True\n",
      "105 True\n",
      "106 True\n",
      "107 True\n",
      "108 True\n",
      "109 True\n",
      "110 True\n",
      "111 True\n",
      "112 True\n",
      "113 True\n",
      "114 True\n",
      "115 True\n",
      "116 True\n",
      "117 True\n",
      "118 True\n",
      "119 True\n",
      "120 True\n",
      "121 True\n",
      "122 True\n",
      "123 True\n",
      "124 True\n",
      "125 True\n",
      "126 True\n",
      "127 True\n",
      "128 True\n",
      "129 True\n",
      "130 True\n",
      "131 True\n",
      "132 True\n",
      "133 True\n",
      "134 True\n",
      "135 True\n",
      "136 True\n",
      "137 True\n",
      "138 True\n",
      "139 True\n",
      "140 True\n",
      "141 True\n",
      "142 True\n",
      "143 True\n",
      "144 True\n",
      "145 True\n",
      "146 True\n",
      "147 True\n",
      "148 True\n",
      "149 True\n",
      "150 True\n",
      "151 True\n",
      "152 True\n",
      "153 True\n",
      "154 True\n",
      "155 True\n",
      "156 True\n",
      "157 True\n",
      "158 True\n",
      "159 True\n",
      "160 True\n",
      "161 True\n",
      "162 True\n",
      "163 True\n",
      "164 True\n",
      "165 True\n",
      "166 True\n",
      "167 True\n",
      "168 True\n",
      "169 True\n",
      "170 True\n",
      "171 True\n",
      "172 True\n",
      "173 True\n",
      "174 True\n",
      "175 True\n",
      "176 True\n",
      "177 True\n",
      "178 True\n",
      "179 True\n",
      "180 True\n",
      "181 True\n",
      "182 True\n",
      "183 True\n",
      "184 True\n",
      "185 True\n",
      "186 True\n",
      "187 True\n",
      "188 True\n",
      "189 True\n",
      "190 True\n",
      "191 True\n",
      "192 True\n",
      "193 True\n",
      "194 True\n",
      "195 True\n",
      "196 True\n",
      "197 True\n",
      "198 True\n",
      "199 True\n"
     ]
    }
   ],
   "source": [
    "def genNew(n):\n",
    "    new_n = 0\n",
    "    while n > 0:\n",
    "        new_n = new_n + n % 10\n",
    "        n = n // 10\n",
    "    return new_n\n",
    "\n",
    "for i in range(100, 200):\n",
    "    n = i\n",
    "    while n > 9:\n",
    "        n = genNew(n)\n",
    "    print(i, (i-1) % 9 + 1 == n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
